/******************************************************************************************
 * 
 * Simulate the syscall funtions in source process' platform by invoking the native syscall
 * function. There the <code>operator ()</code> is redirected.
 *
 ******************************************************************************************/
#ifndef MIPSSIGNALREGISTER_H
#define MIPSSIGNALREGISTER_H

#include "crossbit/SignalRegister.h"
#include <signal.h>
#include "arch/mips/MIPSSignalInternal.h"
#include "crossbit/UTIL.h"
//#include "crossbit/SYSCALL.h"

namespace crossbit {

    //class ProcessorState;
    //class MemoryImage;
	//class SignalHandler;

    class MIPSSignalRegister : public SignalRegister {
        public:
            MIPSSignalRegister() { UTIL::XTMemset((void*)&sig_fn_table, 0, sizeof(sig_fn_table)); }
            ~MIPSSignalRegister(){}

			XTInt32 regSignalHandler(XTInt32 mips_sig_num, XTMemAddr mips_sig_h);
			XTInt32 regRTSignalHandler(XTInt32 mips_sig_num, XTMemAddr mips_rt_sig_h);
			XTInt32 regSigactionHandler(XTInt32 mips_sig_num, XTMemAddr mips_act, XTMemAddr mips_oldact);
			XTInt32 regRTSigactionHandler(XTInt32 mips_sig_num, XTMemAddr mips_act, XTMemAddr mips_oldact);

			XTInt32 convertSigNum2Host(XTInt32 mips_sig_num);
			XTUint32 convertSaFlags2Host(XTUint32 mips_sa_flags);
			XTInt32 convertSbHow2Host(XTInt32 mips_sb_how); 
			void convertSaMask2Host(XTUint32 *mips_sa_mask, XTUint32 *local_sa_mask);			//On different platform, signal number is different.
																								//So mask bits is different also.	
																								//x86 is 64 bits, mips is 128 bits
																							
																								
			void setHandlerSPC(XTInt32 mips_sig_num, XTMemAddr handler_SPC)
			{
				//UTIL::XTLOG("setSPC: %x\n",handler_SPC);
				sig_fn_table[mips_sig_num - 1] = handler_SPC;
			}

			XTMemAddr getHandlerSPC(XTInt32 mips_sig_num)
			{
				//UTIL::XTLOG("getSPC: %x\n",sig_fn_table[mips_sig_num - 1]);
				return sig_fn_table[mips_sig_num - 1];
			}

		private:
			XTMemAddr sig_fn_table[MIPS__NSIG];

    };

}
#endif
